<script src="lib/js/zepto.min.js"></script>


<!--<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>-->
<script src="lib/js/googlemap.api.js"></script>
<script>

    (function ($, window) {
        var map;
        var oMapContainer = document.getElementById("map-canvas");
		google.maps.event.addDomListener(window, 'load', function(){
			getUsrLocation(function (latitude, longitude) {
				getTheMap(latitude, longitude, map, oMapContainer);
			});
			//getTheMap(23.129163000000002, 113.26443499999999,map, oMapContainer);
		});

        //oMapContainer:放地图的容器
        function getTheMap(latitude, longitude, map, oMapContainer) {
            var mapOptions = {
                zoom: 14
            };
            var map = new google.maps.Map(oMapContainer, mapOptions);
            var pos = new google.maps.LatLng(latitude, longitude);
            //position上显示label窗
            var infowindow = new google.maps.InfoWindow({
                map: map,
                position: pos,
                content: '这是某个地方.'
            });
            //跳到地点
            map.setCenter(pos);
        }
        //获取用户位置
        function getUsrLocation(call) {
            //假如浏览器不支持HTML5
            if (!navigator.geolocation) {
				console.log("不支持HTML5");
                handleNoGeolocation(false);
                return;
            }
            navigator.geolocation.getCurrentPosition(function (position) {
                //成功
                console.log(position);
                if (!call) {
					console.log("!call");
                    return {
                        latitude: position.coords.latitude,
                        longitude: position.coords.longitude
                    }
                }
                //回调map api
                call(position.coords.latitude, position.coords.longitude);

            }, function (msg) {
                //出错
                console.log(msg.message);
                handleNoGeolocation(true, msg);
                return;
            });
        }
        //需要获取用户位置而失败时,显示默认位置
        function handleNoGeolocation(errorFlag, msg) {
            if (errorFlag) { var content = '无法获取您的位置信息'; } else { var content = '无法获取您的位置信息'; }
            var map = new google.maps.Map(oMapContainer, { zoom: 1 });
            var options = {
                map: map,
                position: new google.maps.LatLng(60, 105),
                content: content
            };
            var infowindow = new google.maps.InfoWindow(options);
            map.setCenter(options.position);
        }
    })(Zepto, window);



</script>